package com.family.service.impl;

import com.family.mapper.GenerationMapper;
import com.family.mapper.NameMapper;
import com.family.mapper.UserMapper;
import com.family.model.Generation;
import com.family.model.User;
import com.family.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;
    private NameMapper nameMapper;
    private GenerationMapper generationMapper;

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setNameMapper(NameMapper nameMapper) {
        this.nameMapper = nameMapper;
    }

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setGenerationMapper(GenerationMapper generationMapper) {
        this.generationMapper = generationMapper;
    }

    @Override
    public User addUser(User user) {
        userMapper.addUser(user);
        return user;
    }

    @Override
    public User updateUser(User user) {
        userMapper.updateUser(user);
        return user;
    }

    @Override
    public User getUserByWechatId(String wechatId) {
        return userMapper.getUserByWechatId(wechatId);
    }

    @Override
    public User getUserById(int userId) {
        User user = userMapper.getUserById(userId);
        return user;
    }

    @Override
    public List<User> queryUsersById(int userId) {
        return userMapper.queryUsersById(userId);
    }


    /**
     * 根据名字查询同名用户
     *
     * @param name
     * @param status 是否被认证 0:all,1:已经认证，2:未认证
     * @return
     */
    @Override
    public List<User> queryUsersByName(String name, int status) {
        return userMapper.queryUsersByName(name, status);
    }

    @Override
    public PageInfo<User> queryUsersLikeName(String name, int index, int pageSize) {
        PageHelper.startPage(index,pageSize);
        List<User> users = userMapper.queryUsersLikeName(name);
        PageInfo<User> page = new PageInfo<>(users);
        return page;
    }
}
